<template>
  <add @submit="addp"></add>
</template>
<script>
import add from "@/components/addChong";
import PetownersApi from "@/services/Petowners";
export default {
  data() {
    return {
      petArr: []
    };
  },
  components: {
    add
  },
  async created() {
    const res = await PetownersApi.getPetownersById(this.$route.params.id);
    this.petArr = res.data.pet;
  },
  methods: {
   async addp(p) {
    await PetownersApi.addpet({
        _id: this.$route.params.id,
        pet: [...this.petArr,p]
      });
      this.$message({
        message: "添加成功",
        type: "success",
        onClose: () => {
          this.$router.push({
            name: "查看宠物"
          });
        }
      });
    }
  }
};
</script>

